import { Plugin } from "../../core";
import { ReactElement } from "react";

export interface RenderShowSearchPopoverProps {
  onClick: () => void;
}

export interface RenderSearchProps {
  clearKeyword(): void;
  changeMatchCase(matchCase: boolean): void;
  changeWholeWords(wholeWords: boolean): void;
  currentMatch: number;
  jumpToNextMatch(): void;
  jumpToPreviousMatch(): void;
  keyword: string;
  matchCase: boolean;
  numberOfMatches: number;
  wholeWords: boolean;
  search(): void;
  setKeyword(keyword: string): void;
}

export interface ShowSearchPopoverProps {
  children?: (props: RenderShowSearchPopoverProps) => ReactElement;
}

export interface SearchProps {
  children?: (props: RenderSearchProps) => ReactElement;
}

export interface FlagKeyword {
  keyword: string;
  matchCase?: boolean; // `false` by default
  wholeWords?: boolean; // `false` by default
}

export type SingleKeyword = string | RegExp | FlagKeyword;

export interface OnHighlightKeyword {
  highlightEle: HTMLElement;
  keyword: RegExp;
}

export interface SearchPluginProps {
  // The keyword that will be highlighted in all pages
  keyword?: SingleKeyword | SingleKeyword[];
  onHighlightKeyword?(props: OnHighlightKeyword): void;
}

export interface SearchPlugin extends Plugin {
  Search(props: SearchProps): ReactElement;
  ShowSearchPopover(props: ShowSearchPopoverProps): ReactElement;
  ShowSearchPopoverButton(): ReactElement;
  clearHighlights(): void;
  highlight(keyword: SingleKeyword | SingleKeyword[]): void;
  jumpToNextMatch(): void;
  jumpToPreviousMatch(): void;
}
